<admintpl file="header" />
</head>
<style>
    .input_edit{
        width:120px;
    }
    .span3{
        margin-bottom: 20px;
    }
</style>
<body>
<div class="wrap js-check-wrap">
    <div class="wrap js-check-wrap">
        <if condition="$admin_id eq 1">
            <div style="width: 400px; height: 250px;">
                <form class="form-search" id="query_form" method="post" action="{:U('Admin/SensitiveWords/addWords')}" enctype="multipart/form-data">

                    <div class="control-group">
                        <label class="span1 control-label" style="width: 90px;">添加敏感词：</label>
                        <div class="span3">
                            <textarea name="words" id="words" rows="5"></textarea>
                        </div>
                    </div>

                    <div class="control-group">
                        <label class="span1 control-label" style="width: 90px;">上传文件：</label>
                        <div class="span3">
                            <input type="file" name="words_file" id="words_file">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="span1 control-label" style="width: 90px;"></label>
                        <div class="span3">
                            <input type="hidden" name="keyword" value="add" id="keyword">
                            <input type="submit" id="form-submit"  class="btn btn-primary" value="添加" />
                        </div>
                    </div>

                </form>
            </div>
        </if>
        <!--<div style="width: 90%">-->
            <form class="form-search" id="query_form1" method="post" action="{:U('Admin/SensitiveWords/index')}">

                <div class="control-group">
                    <label class="span1 control-label" style="width: 90px;">搜索敏感词：</label>
                    <div class="span3">
                        <input type="text" name="find_words" id="find_word" value="{$find_words}">
                    </div>
                </div>

                <div class="control-group">
                    <label class="span1 control-label" style="width: 90px;"></label>
                    <div class="span3">
                        <input type="submit" data-action="{:U('Admin/SensitiveWords/index')}" class="btn btn-primary" value="搜索" />
                    </div>
                </div>

            </form>
        <!--</div>-->
<br>
        <div class="span3" style="clear: both;">
            <if condition="$admin_id eq 1">
                <input type="button" class="btn btn-primary" id="del_words" value="删除敏感词" />
            </if>
        </div>
        <form class="js-ajax-form" action="" method="post">
            <table class="table table-hover table-bordered" style="width: 30%; clear: both;">
                <thead>
                <tr>
                    <th style="width: 15%;">
                        <if condition="$admin_id eq 1">
                            <input type="checkbox" id="all"> 全选
                        </if>
                    </th>
                    <th>序号</th>
                    <th>敏感词</th>
                </tr>
                </thead>
                <tbody>
                <foreach name="words_list" item="words" key="key">
                    <tr>
                        <td><if condition="$admin_id eq 1"><input name="words_id[]" class="words_id"  type="checkbox" value="{$words.id}"></if></td>
                        <td><?php echo ($currentPage-1)*30+$key+1?></td>
                        <td>{$words.words}</td>
                    </tr>
                </foreach>

                </tbody>
            </table>
        </form>
        <div class="pagination">{$page}</div>
    </div>

</div>
<script src="__PUBLIC__/js/common.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>

    $("#all").click(function(){
        if(this.checked){
            $(".words_id").each(function() {
                this.checked = true;
            });
        }else{
            $(".words_id").each(function() {
                this.checked = false;
            });
        }
    });

    $("#del_words").click(function () {
        var boxes = $("[name='words_id[]']");
        var words_checbox = [];
        for(i=0;i<boxes.length;i++){
            if(boxes[i].checked == true){
                words_checbox.push(boxes[i].value);
            }
        }

        if(words_checbox == ''){
            alert('请选择要删除的敏感词!');
            return false;
        }

        if(confirm('确认删除选中的敏感词？')){
            $.post("<?php echo U('Admin/SensitiveWords/delWords')?>",{
                words_checbox:words_checbox},function(result){
                if(result > '0'){
                    var msg = '删除成功';
                }else{
                    var msg = '删除失败';
                }
                alert(msg);
                $(".words_id").each(function() {
                    this.checked = false;
                });
                $("#all").checked = false;
                window.location.href = "<?php echo U('Admin/SensitiveWords/index')?>";
            });
        }
    })
</script>

</body>
</html>